< previous page page_631 next page >

Page 631
The fields that relate to employee skills need to be separated from the others in the table. You don't need to put all 12 skill fields in the new table, though. You only need one of each of the unique data fields. The new database now has not one, but two data tables. One, called Skills, contains only the skill fields. The other table, called Employees, contains the rest of the fields. Table 16.1 shows how the two new tables look.
Table 16.1. Eliminating repeating data.
Skills TableEmployees Table
EmpIDEmpID
SkillCodeEmpName
SkillNameDeptID
SkillDeptIDDeptName
SkillLevelDeptLocation

Notice that the first field in both tables is the EmpID field. This field is used to relate the two tables. Each record in the Skill table contains the employee ID and all pertinent data on a single job skill (code, name, department learned, and ability level). If a single employee has several skills, there is a single record in the Skill table for each job skill acquired by an employee. For example, if a single employee has acquired five skills, there are five records with the same employee ID in the Skills table.
Each record in the Skills table must contain a valid value in the EmpID field or it should be rejected. In other words, each time a record is added to the Skills table, the value in the EmpID field should be checked against values in the EmpID field of the Employees table. If no match is found, the Skills record must be corrected before it is written to the database. You remember from the discussion of SQL Data Definition Language statements on Day 13 that this is a FOREIGN KEY CONSTRAINT. The field EmpID in the Skills table is a foreign key that references the field EmpID in the Employees table. Also, the EmpID field in the Employees table should be a primary field to make sure that each record in the Employee table has a unique EmpID value.
Now that you know the fields and index constraints you need, you can use SQL DDL to create two new tables. If you have not already done so, start the Visdata application and open the NORMDAT1.MDB database. Now you create two new tables that bring the database into compliance with the first rule of data normalization.
First, create the table that holds all the basic employee data. This table has all the fields that were in the Table1 table, minus the skill fields. Using the information in Table 16.1 as a guide, enter an SQL DDL statement in the SQL window of Visdata that creates the Employees data table. Your SQL statement should resemble Listing 16.1.

 
< previous page page_631 next page >

If you like this book, buy it!